package com.magima.core.prompt;

import java.util.ArrayList;
import java.util.List;

import com.magima.core.app.IPromptEntry;
import com.magima.core.app.IPromptManager;

import android.content.Context;
import android.os.Handler;

public class DefaultPromptManager implements IPromptManager{
	private List<IPromptEntry> roots;
	private PromptStructrueBuilder builder;
	private Handler mHandler;
	
	public DefaultPromptManager(PromptStructrueBuilder builder){
		this.roots = new ArrayList<IPromptEntry>();
		this.builder = builder;
		mHandler = new Handler();
	}
	
	@Override
	public void init(Context context) {
		builder.builder(this, context);
	}
	
	@Override
	public void addRoot(IPromptEntry entry){
		roots.add(entry);
	}

	@Override
	public void removeRoot(IPromptEntry entry){
		roots.remove(entry);
	}

	@Override
	public IPromptEntry getRoot(int index){
		return roots.get(index);
	}

	@Override
	public IPromptEntry findByName(String name){
		for ( IPromptEntry root : roots ){
			IPromptEntry ret = root.findByName(name);
			if ( ret != null )
				return ret;
		}
		return null;
	}

	@Override
	public Handler gethandler() {
		return mHandler;
	}
}
